home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 8.7 KB | 306 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWPushBu.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWPUSHBU_H
- #include "FWPushBu.h"
- #endif
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- #ifndef FWPART_H
- #include "FWPart.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWRRCSHP_H
- #include "FWRRcShp.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- #ifndef SOM_ODTransform_xh
- #include <Trnsform.xh>
- #endif
-
- //========================================================================================
- // Runtime Informations
- //========================================================================================
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwgadgts
- #endif
-
- FW_DEFINE_CLASS_M1(FW_CPushButton, FW_CButton)
- FW_REGISTER_ARCHIVABLE_CLASS(FW_LPushButton, FW_CPushButton, FW_CPushButton::Read, FW_CGadget::Write)
-
- //========================================================================================
- // CLASS FW_CPushButton
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CPushButton::FW_CPushButton
- //----------------------------------------------------------------------------------------
-
- FW_CPushButton::FW_CPushButton(Environment* ev,
- FW_CView* container, ODID id,
- const FW_CRect& bounds,
- const FW_CString& label) :
- FW_CButton(ev, container, id, bounds),
- fIsDefault(FALSE),
- fButtonHelper(NULL)
- {
-
- #ifdef FW_BUILD_MAC
- fButtonHelper = new FW_CPrivMacPushButtonHelper
- (ev, FW_TYPEID_FROM_TYPE(FW_CPrivMacPushButtonHelper), this);
- #endif
-
- #ifdef FW_BUILD_WIN
- fButtonHelper = new FW_CPrivWinPushButtonHelper
- (ev, FW_TYPEID_FROM_TYPE(FW_CPrivWinPushButtonHelper), this);
- #endif
-
- fButtonHelper->SetText(label);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPushButton::FW_CPushButton
- //----------------------------------------------------------------------------------------
-
- FW_CPushButton::FW_CPushButton(Environment* ev,
- FW_CReadableStream& archive) :
- FW_CButton(ev, archive)
- {
- #ifdef FW_BUILD_MAC
- fButtonHelper
- = new FW_CPrivMacPushButtonHelper
- (ev, FW_TYPEID_FROM_TYPE(FW_CPrivMacPushButtonHelper), this);
- #endif
-
- #ifdef FW_BUILD_WIN
- fButtonHelper = new FW_CPrivWinPushButtonHelper
- (ev, FW_TYPEID_FROM_TYPE(FW_CPrivWinPushButtonHelper), this);
- #endif
-
- FW_CDynamicString label;
-
- archive >> fIsDefault;
- FW_CStringArchiver::Read(archive, label);
-
- fButtonHelper->SetText(label);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPushButton::~FW_CPushButton
- //----------------------------------------------------------------------------------------
-
- FW_CPushButton::~FW_CPushButton()
- {
- delete fButtonHelper;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPushButton::LocationChanged
- //----------------------------------------------------------------------------------------
-
- void FW_CPushButton::LocationChanged(Environment* ev, const FW_CPoint &oldLocation)
- {
- FW_UNUSED(oldLocation);
-
- #ifdef FW_BUILD_WIN
- FW_CViewContext fc(ev, this, GetFrame(ev)->GetActiveFacet(ev));
-
- FW_SPlatformPoint wndLocation = fc.ContentToCanvas(GetLocation(ev));
- FW_SPlatformPoint wndSize = fc.ContentToCanvas(GetSize(ev).x, GetSize(ev).y);
- fButtonHelper->Move(wndLocation, wndSize);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPushButton::SizeChanged
- //----------------------------------------------------------------------------------------
-
- void FW_CPushButton::SizeChanged(Environment* ev, const FW_CPoint &oldSize)
- {
- FW_UNUSED(oldSize);
-
- #ifdef FW_BUILD_WIN
- FW_CViewContext fc(ev, this, GetFrame(ev)->GetActiveFacet(ev));
-
- FW_SPlatformPoint wndLocation = fc.ContentToCanvas(GetLocation(ev));
- FW_SPlatformPoint wndSize = fc.ContentToCanvas(GetSize(ev).x, GetSize(ev).y);
- fButtonHelper->Move(wndLocation, wndSize);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPushButton::Draw
- //----------------------------------------------------------------------------------------
-
- void FW_CPushButton::Draw(Environment* ev, ODFacet* facet, ODShape* invalidShape)
- {
- #ifdef FW_BUILD_MAC
- FW_CViewContext gc(ev, this, facet, invalidShape);
-
- ODPlatformWindow window = gc.GetFacet()->GetWindow(ev)->GetPlatformWindow(ev);
-
- FW_SPlatformPoint qdPoint = gc.LogicalToDevice(FW_kZeroPoint);
- FW_SPlatformPoint qdSize;
- GetSize(ev).AsPlatformPoint(qdSize);
- fButtonHelper->Draw(window, qdPoint, qdSize);
-
- if (fIsDefault)
- {
- // Draw the standard default button border
-
- FW_CFixed buttonOval = FW_IntToFixed(2) + GetSize(ev).y.Half();
- FW_CRoundRectShape::RenderRoundRect(
- gc,
- FW_CRect(FW_kZeroPoint, GetSize(ev)),
- FW_CPoint(buttonOval, buttonOval),
- FW_kFrame,
- FW_kNormalInk,
- FW_PStyle(FW_IntToFixed(3)));
- }
- #endif
-
- #ifdef FW_BUILD_WIN
- // Windows handles updating controls automatically
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPushButton::DoMouseDown
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CPushButton::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
- {
- // This code is duplicated for in each control class, think about moving it to the
- // control helpers, and maybe making the owner of helpers be gadgets. [AMB]
-
- #ifdef FW_BUILD_MAC
- ODFacet* odFacet = theMouseEvent.GetFacet(ev);
- FW_CViewContext gc(ev, this, odFacet);
-
- FW_CPoint canvasWhere = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kWindow);
-
- {
- // Take into account the origin offset for pattern alignment. [AMB]
- FW_CAcquiredODTransform aqTransform(odFacet->CreateTransform(ev));
-
- ODPlatformCanvas plfmCanvas = gc.GetPlatformCanvas();
- FW_CPoint offset(
- FW_IntToFixed(plfmCanvas->portRect.left),
- FW_IntToFixed(plfmCanvas->portRect.top));
-
- ODPoint odOffset = offset;
- aqTransform->MoveBy(ev, &odOffset);
-
- canvasWhere.Transform(ev, aqTransform);
- }
-
- FW_SPlatformPoint qdControlPosition = gc.LogicalToDevice(FW_kZeroPoint);
- FW_SPlatformPoint qdWhere;
- canvasWhere.AsPlatformPoint(qdWhere);
- ODPlatformWindow window = odFacet->GetWindow(ev)->GetPlatformWindow(ev);
-
- FW_SPlatformPoint qdSize;
- GetSize(ev).AsPlatformPoint(qdSize);
-
- return fButtonHelper->MouseDown(window, qdWhere, qdControlPosition, qdSize);
- #endif
-
- #ifdef FW_BUILD_WIN
- // Windows handles mouse events automatically
- return FALSE;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPushButton::SetDefault
- //----------------------------------------------------------------------------------------
-
- void FW_CPushButton::SetDefault(Environment* ev, FW_Boolean isDefault)
- {
- if (isDefault != fIsDefault)
- {
- fIsDefault = isDefault;
- fButtonHelper->MakeDefaultButton(fIsDefault);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPushButton::ButtonPressed
- //----------------------------------------------------------------------------------------
-
- void FW_CPushButton::ButtonPressed(Environment* ev)
- {
- // ----- Notify interested parties of that the button was pressed
-
- FW_CButtonPressedNotification notification(FW_CInterest(this, GetButtonPressedNotificationToken(ev)),
- GetIdentifier(ev), 1);
- Notify(notification);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPushButton::Flatten
- //----------------------------------------------------------------------------------------
-
- void FW_CPushButton::Flatten(FW_CWritableStream& archive) const
- {
- FW_CDynamicString label;
- fButtonHelper->GetText(label);
-
- FW_CGadget::Flatten(archive);
-
- archive << fIsDefault;
- FW_CStringArchiver::Write(archive, label);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPushButton::Read
- //----------------------------------------------------------------------------------------
-
- void* FW_CPushButton::Read(FW_CReadableStream& archive)
- {
- Environment* ev = ::somGetGlobalEnvironment();
- return new FW_CPushButton(ev, archive);
- }
-